source ~/.bash_profile

# ssh配置
DEPLOY_USER=root
DEPLOY_PORT=22
# 钉钉告警配置
ACCESS_TOKEN=e9526eb327a1c1d731518db1593c623bcd240ee3fd4f0dee0feb63d0dabd6fe6

for DEPLOY_HOST in ${DEPLOY_HOSTS[@]}; do

# 钉钉提醒-部署开始
curl -fsSL https://gitee.com/hdzhangQAQ/twisly-riptide-doc/raw/master/shell/deploy/tool_send_ding.sh | \
  SERVER_LABEL=前端项目 \
  SERVER_NAME=${SERVER_NAME} \
  PROCESS=部署开始 \
  DEPLOY_HOST=${DEPLOY_HOST} \
  PROFILE=${PROFILE} \
  BUILD_USER=${BUILD_USER} \
  ACCESS_TOKEN=${ACCESS_TOKEN} \
sh -

# 安装依赖
yarn install
# 打包
yarn run build

# 压缩, 提高零散小文件传输效率
rm -rf czvf ${SERVER_NAME}.tar.gz
mv dist ${SERVER_NAME}
tar -czvf ${SERVER_NAME}.tar.gz ${SERVER_NAME}

# 远程传输
scp -P ${DEPLOY_PORT} -r ${SERVER_NAME}.tar.gz ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DEPLOY_PATH}
# 文件清理
rm -rf ${SERVER_NAME}.tar.gz
rm -rf ${SERVER_NAME}

# 解压部署
ssh -p ${DEPLOY_PORT} ${DEPLOY_USER}@${DEPLOY_HOST} <<EOF
  tar -xzvf ${REMOTE_DEPLOY_PATH}/${SERVER_NAME}.tar.gz -C ${REMOTE_DEPLOY_PATH}
  rm -rf ${REMOTE_DEPLOY_PATH}/${SERVER_NAME}.tar.gz
EOF

# 钉钉提醒-部署成功
curl -fsSL https://gitee.com/hdzhangQAQ/twisly-riptide-doc/raw/master/shell/deploy/tool_send_ding.sh | \
  SERVER_LABEL=前端项目 \
  SERVER_NAME=${SERVER_NAME} \
  PROCESS=部署成功 \
  DEPLOY_HOST=${DEPLOY_HOST} \
  PROFILE=${PROFILE} \
  BUILD_USER=${BUILD_USER} \
  ACCESS_TOKEN=${ACCESS_TOKEN} \
sh -

done